package com.jwgf.decoration;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
 * Created by Jacky on 2018/4/2.
 */

public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    private int spaceVertical;
    private int spaceHorizontal;

    public SpaceItemDecoration(int spaceVertical, int spaceHorizontal) {
        this.spaceVertical = spaceVertical;
        this.spaceHorizontal = spaceHorizontal;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//        super.getItemOffsets(outRect, view, parent, state);
        outRect.left = spaceHorizontal;
        outRect.right = spaceHorizontal;
        outRect.bottom = spaceVertical;

        // Add top margin only for the first item to avoid double space between items
//        if(parent.getChildAdapterPosition(view) == 0)
            outRect.top = spaceVertical;
    }
}
